package com.ktjy.web;

import com.ktjy.entity.User;
import com.ktjy.service.UserService;
import com.ktjy.service.impl.UserServiceImpl;
import my.framework.anno.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理和用户相关的请求
 */
public class UserController {
    @RequestMapping("/user/doRegister")
    public String register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         String  userName= request.getParameter("username");
         String  userPassword= request.getParameter("userpassword");
         String  userCardNo= request.getParameter("usercardno");
         String  userTel= request.getParameter("usertel");
         String  userAddress= request.getParameter("useraddress");
         String  userPostNumber= request.getParameter("userpostnumber");

         User user=new User(userName,userPassword,userCardNo,userTel,userAddress,userPostNumber);
        //调用Service登录方法
        UserService userService=new UserServiceImpl();
        int ret = userService.register(user);
        if(ret>0){
                //进入普通用户界面
                request.getRequestDispatcher("/login.jsp").forward(request,response);
        }
        return "redirect:/fail.jsp";//重定向
    }
}
